#include<iostream>
#include<signal.h>
#include<unistd.h>


void prinBlock()
{
    sigset_t block,oblock;
    sigemptyset(&block);
    sigemptyset(&oblock);

    sigprocmask(SIG_SETMASK,&block,&oblock);

    std::cout<<"Block";
    for(int signo=31;signo>0;signo--)
    {
        if(sigismember(&oblock,signo))
        {
            std::cout<<"1";
        }
        else{
            std::cout<<"0";
        }
    }
    std::cout<<std::endl;
}

void Pending()
{
    sigset_t pending;
    ::sigpending(&pending);

    std::cout<<"Pending";
    for(int signo=31;signo>0;signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout<<"1";
        }
        else{
            std::cout<<"0";
        }
    }
    std::cout<<std::endl;

}

void handler(int signo)
{
    int count=0;
    count++;
    while (1)
    {
        /* code */
        std::cout<<"get is sig: "<<signo<<std::endl;
        sleep(1);
    }
    
    exit(1);
}
int main()
{
    struct sigaction act,oldact;
    act.sa_handler=handler;
    ::sigaction(2,&act,&oldact);

    while (1)
    {
        /* code */
        prinBlock();
        pause();
    }
    
    return 0;
}